package com.jikangjun.disk.file.entity;

import java.util.Date;


public class FileCopyOperation {

    /**
     * 操作ID
     */
    private String operationId;

    /**
     * 源文件键
     */
    private String sourceFileKey;

    /**
     * 源文件名
     */
    private String sourceFileName;

    /**
     * 目标文件键
     */
    private String targetFileKey;

    /**
     * 目标文件名
     */
    private String targetFileName;

    /**
     * 目标路径
     */
    private String targetPath;

    /**
     * 文件大小
     */
    private long fileSize;

    /**
     * 操作状态：PENDING（待处理）、PROCESSING（处理中）、SUCCESS（成功）、FAILED（失败）
     */
    private String status;

    /**
     * 操作类型：COPY（复制）、MOVE（移动）
     */
    private String operationType;

    /**
     * 操作用户ID
     */
    private String userId;

    /**
     * 操作用户名
     */
    private String userName;

    /**
     * 操作开始时间
     */
    private Date startTime;

    /**
     * 操作完成时间
     */
    private Date endTime;

    /**
     * 操作耗时（毫秒）
     */
    private long duration;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 错误代码
     */
    private String errorCode;

    /**
     * 是否覆盖
     */
    private boolean overwrite;

    /**
     * 操作进度（百分比）
     */
    private int progress;

    // 默认构造函数
    public FileCopyOperation() {
        this.startTime = new Date();
        this.status = "PENDING";
        this.progress = 0;
    }

    // 带参数的构造函数
    public FileCopyOperation(String sourceFileKey, String targetPath, String userId) {
        this.sourceFileKey = sourceFileKey;
        this.targetPath = targetPath;
        this.userId = userId;
        this.startTime = new Date();
        this.status = "PENDING";
        this.progress = 0;
    }

    // Getters and Setters
    public String getOperationId() {
        return operationId;
    }

    public void setOperationId(String operationId) {
        this.operationId = operationId;
    }

    public String getSourceFileKey() {
        return sourceFileKey;
    }

    public void setSourceFileKey(String sourceFileKey) {
        this.sourceFileKey = sourceFileKey;
    }

    public String getSourceFileName() {
        return sourceFileName;
    }

    public void setSourceFileName(String sourceFileName) {
        this.sourceFileName = sourceFileName;
    }

    public String getTargetFileKey() {
        return targetFileKey;
    }

    public void setTargetFileKey(String targetFileKey) {
        this.targetFileKey = targetFileKey;
    }

    public String getTargetFileName() {
        return targetFileName;
    }

    public void setTargetFileName(String targetFileName) {
        this.targetFileName = targetFileName;
    }

    public String getTargetPath() {
        return targetPath;
    }

    public void setTargetPath(String targetPath) {
        this.targetPath = targetPath;
    }

    public long getFileSize() {
        return fileSize;
    }

    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getOperationType() {
        return operationType;
    }

    public void setOperationType(String operationType) {
        this.operationType = operationType;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public boolean isOverwrite() {
        return overwrite;
    }

    public void setOverwrite(boolean overwrite) {
        this.overwrite = overwrite;
    }

    public int getProgress() {
        return progress;
    }

    public void setProgress(int progress) {
        this.progress = progress;
    }

    /**
     * 计算操作耗时
     */
    public void calculateDuration() {
        if (this.endTime != null && this.startTime != null) {
            this.duration = this.endTime.getTime() - this.startTime.getTime();
        }
    }

    /**
     * 完成操作
     */
    public void complete() {
        this.endTime = new Date();
        this.calculateDuration();
        this.progress = 100;
    }

    /**
     * 设置操作失败
     */
    public void fail(String errorMessage, String errorCode) {
        this.status = "FAILED";
        this.errorMessage = errorMessage;
        this.errorCode = errorCode;
        this.complete();
    }

    /**
     * 设置操作成功
     */
    public void success() {
        this.status = "SUCCESS";
        this.complete();
    }

    @Override
    public String toString() {
        return "FileCopyOperation{" +
                "operationId='" + operationId + '\'' +
                ", sourceFileKey='" + sourceFileKey + '\'' +
                ", sourceFileName='" + sourceFileName + '\'' +
                ", targetFileKey='" + targetFileKey + '\'' +
                ", targetFileName='" + targetFileName + '\'' +
                ", targetPath='" + targetPath + '\'' +
                ", fileSize=" + fileSize +
                ", status='" + status + '\'' +
                ", operationType='" + operationType + '\'' +
                ", userId='" + userId + '\'' +
                ", userName='" + userName + '\'' +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", duration=" + duration +
                ", errorMessage='" + errorMessage + '\'' +
                ", errorCode='" + errorCode + '\'' +
                ", overwrite=" + overwrite +
                ", progress=" + progress +
                '}';
    }
}